package com.chenfan.process.entity.dto;

import com.chenfan.process.entity.po.ProcessPo;
import com.chenfan.process.entity.po.ProcessRelatedPo;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author K
 * @date 2022/10/9 1:35 PM
 */
@Data
public class InstanceSnapshotDTO {

    /**
     * 关联关系
     */
    private List<ProcessRelatedPo> processRelatedPoList;

    /**
     * 节点快照
     */
    private List<ProcessPo> processList;

    public Map<Long, ProcessPo> ofProcessMap() {
        return processList.stream().collect(Collectors.toMap(e -> e.getId(), e -> e, (e1, e2) -> e2));
    }

    public ProcessPo findByProcessId(Long processId) {
        for(ProcessPo p: processList) {
            if (p.getId().equals(processId)) {
                return p;
            }
        }
        return null;
    }

    public List<ProcessPo> listByIds(List<Long> processIds) {
        List<ProcessPo> pList = new ArrayList<>();
        for(ProcessPo p: processList) {
            if (processIds.contains(p.getId())) {
                pList.add(p);
            }
        }
        return pList;
    }
}
